home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / comm / tcp / daytimedemo.lha / daytimedemo / startup.c < prev   
C/C++ Source or Header  |  2001-04-08  |  2KB  |  86 lines

  1. /*
  2.  * startup.c
  3.  *
  4.  * THIS ROUTINE IST INTENDED FOR MAXON C/C++ COMPILER ONLY !!!
  5.  *  + faster startup
  6.  *  + smaller code
  7.  *  - disables C++ mode (not really a drawback ;-)
  8.  *  - disables startup modules (library auto-opening, etc.)
  9.  *
  10.  * MAKE SURE TO LINK THIS MODULE WITH HIGHEST PRIORITY,
  11.  * AND TO LINK THE PROGRAM WITHOUT STARTUP CODE
  12.  *
  13.  * DO NOT USE IT WITH ANY OTHER COMPILER THAN MAXON C/C++
  14.  */
  15.  
  16. #ifdef __MAXON__
  17.  
  18. #include <pragma/exec_lib.h>
  19. #include <exec/alerts.h>
  20. #include <dos/dos.h>
  21. #include <dos/dosextens.h>
  22.  
  23. struct Library *SysBase = NULL, *DOSBase = NULL;
  24. const STRPTR __dosname__ = "dos.library";
  25.  
  26. extern LONG main(LONG c, APTR p);
  27.  
  28. /****************************************************************
  29.     the first routine found by the linker
  30.  
  31.           - make sure to link without startup code
  32.          - make sure to link this module with highest priority
  33.  
  34.          - don't forget, you're limited to ANSI-C now !
  35.  ****************************************************************/
  36. long __launch__(register __d0 LONG Argc, register __a0 APTR Argv)
  37. {
  38.     LONG rw = RETURN_FAIL;
  39.     
  40.     /* fetch ExecBase */
  41.     SysBase = (struct Library *) *((ULONG *) 4);
  42.     
  43.     /* open DOS (KS2.04 minimum) */
  44.     DOSBase = OpenLibrary(__dosname__, 37U);
  45.     if(DOSBase)
  46.     {
  47.         struct Process *thistask;
  48.         
  49.         /* check start-mode */
  50.         thistask = (struct Process *) FindTask(NULL);
  51.         if(thistask->pr_CLI)
  52.         {
  53.             /* run from shell - WARNING: NO ARGUMENT PARSING HERE !!! */
  54.             rw = main(Argc, Argv);
  55.         }
  56.         else
  57.         {
  58.             struct MsgPort *mp = &(thistask->pr_MsgPort);
  59.             struct Message *sm;
  60.             
  61.             /* fetch WBStartupMsg */
  62.             WaitPort(mp);
  63.             sm = GetMsg(mp);
  64.             
  65.             /* run from Workbench - standard arguments */
  66.             main(0L, sm);
  67.             
  68.             /* release WBStartupMsg */
  69.             Forbid();
  70.             ReplyMsg(sm);
  71.         }
  72.         
  73.         /* close DOS */
  74.         CloseLibrary(DOSBase);
  75.     }
  76.     else
  77.     {
  78.         Alert(AG_OpenLib | AO_DOSLib);
  79.     }
  80.     
  81.     /* set return code for shell */
  82.     return(rw);
  83. }
  84.  
  85. #endif
  86.